package cn.com.sp.demo.controller;

import java.util.Date;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.sp.demo.bean.User;
import cn.com.sp.demo.service.IUserService;

@Controller
@RequestMapping(value = "user")
@EnableAutoConfiguration
public class UserController {

	@Autowired
	private IUserService userService;

	private int a = 0;

	private final Lock lock = new ReentrantLock();

	@ResponseBody
	@RequestMapping(value = "addUser")
	public String addUser(User user) {
		userService.addUser(user);
		return "success";
	}

	@ResponseBody
	@RequestMapping(value = "deleteUser")
	public String deleteUser(Integer id) {
		userService.deleteUser(id);
		return "success";
	}

	@ResponseBody
	@RequestMapping(value = "getUser")
	public User getUser(Integer id) {
		return userService.getUser(id);
	}

	@ResponseBody
	@RequestMapping(value = "updateUser")
	public String updateUser(User user) {
		userService.updateUser(user);
		return "success";
	}

}
